package com.study.concurrent.A_ThreadManagement.k_HandlingOfUncontrollableExceptionsInThreadGroups;

import java.util.Random;

/**
 * Created by 赵超 on 2017/3/20.
 */
public class Task implements Runnable {
    /**
     * 在方法中出发AritmethicException异常
     * 用1000除以一个随机数字，当随机数字生成0时，异常将会被抛出
     */
    @Override
    public void run() {
        int result;
        Random random = new Random(Thread.currentThread().getId());
        while (true) {
            result = 1000 / ((int) random.nextDouble() * 1000);
            System.out.printf("%s : %d\n", Thread.currentThread().getId(), result);
            if (Thread.currentThread().isInterrupted()) {
                System.out.printf("线程 %s : 中断", Thread.currentThread().getId());
                return;
            }
        }
    }
}
